package com.usefullc.common.context;

import com.usefullc.common.user.OnlineUser;
import com.usefullc.common.user.OnlineUserManager;

/**
 * @author: Sampson
 * @date: 2022-09-08 15:57
 */
public class ContextManager {

    private static ThreadLocal<Long> tenantThreadLocal = new ThreadLocal<>();

    public static Long getTenantId() {
        OnlineUser loginUser = OnlineUserManager.getLoginUser();
        if(loginUser != null){
            return loginUser.getTenantId();
        }else {
            return tenantThreadLocal.get();
        }
    }

    public static void setTenantId(Long tenantId) {
        tenantThreadLocal.set(tenantId);
    }

    public static void clean() {
        tenantThreadLocal.remove();
    }
}
